Compare widget names as GQuarks in style matching.
authorCarlos Garnacho <carlosg@gnome.org>
Wed, 4 Aug 2010 11:11:50 +0000 (13:11 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 4 Dec 2010 14:37:34 +0000 (15:37 +0100)
gtk/gtkcssprovider.c
gtk/gtkwidgetpath.c
gtk/gtkwidgetpath.h

index 323f397a9c978fec4d6fe727c0b9464405618c94..0f55a862fd7819ffd3986622102d85007e41b7b8 100644 (file)
@@ -433,13 +433,7 @@ compare_selector_element (GtkWidgetPath   *path,
     }
   else if (elem->elem_type == SELECTOR_NAME)
     {
-      const gchar *name, *path_name;
-
-      name = g_quark_to_string (elem->name);
-      path_name = gtk_widget_path_iter_get_name (path, index);
-
-      if (!path_name ||
-          strcmp (path_name, name) != 0)
+      if (!gtk_widget_path_iter_has_qname (path, index, elem->name))
         return FALSE;
 
       *score = 0xF;
index 60dcfa23710bb47fc620f32d91d07c159f84f1c8..db9f79b1be8e379eb368762d478724df378229e0 100644 (file)
@@ -29,7 +29,7 @@ typedef struct GtkPathElement GtkPathElement;
 struct GtkPathElement
 {
   GType type;
-  gchar *name;
+  GQuark name;
   GHashTable *regions;
 };
 
@@ -66,7 +66,7 @@ gtk_widget_path_copy (const GtkWidgetPath *path)
       elem = &g_array_index (path->elems, GtkPathElement, i);
 
       new.type = elem->type;
-      new.name = g_strdup (elem->name);
+      new.name = elem->name;
 
       if (elem->regions)
         {
@@ -98,7 +98,6 @@ gtk_widget_path_free (GtkWidgetPath *path)
       GtkPathElement *elem;
 
       elem = &g_array_index (path->elems, GtkPathElement, i);
-      g_free (elem->name);
 
       if (elem->regions)
         g_hash_table_destroy (elem->regions);
@@ -169,7 +168,7 @@ gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
   g_return_val_if_fail (pos < path->elems->len, NULL);
 
   elem = &g_array_index (path->elems, GtkPathElement, pos);
-  return elem->name;
+  return g_quark_to_string (elem->name);
 }
 
 void
@@ -185,10 +184,42 @@ gtk_widget_path_iter_set_name (GtkWidgetPath *path,
 
   elem = &g_array_index (path->elems, GtkPathElement, pos);
 
-  if (elem->name)
-    g_free (elem->name);
+  elem->name = g_quark_from_string (name);
+}
+
+gboolean
+gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
+                                guint                pos,
+                                GQuark               qname)
+{
+  GtkPathElement *elem;
+
+  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (qname != 0, FALSE);
+  g_return_val_if_fail (pos < path->elems->len, FALSE);
+
+  elem = &g_array_index (path->elems, GtkPathElement, pos);
+
+  return (elem->name == qname);
+}
+
+gboolean
+gtk_widget_path_iter_has_name (const GtkWidgetPath *path,
+                               guint                pos,
+                               const gchar         *name)
+{
+  GQuark qname;
+
+  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (name != NULL, FALSE);
+  g_return_val_if_fail (pos < path->elems->len, FALSE);
+
+  qname = g_quark_try_string (name);
+
+  if (qname == 0)
+    return FALSE;
 
-  elem->name = g_strdup (name);
+  return gtk_widget_path_iter_has_qname (path, pos, qname);
 }
 
 void
index d6e074edec9fc24d6a0e392363cf38bdd7487519..e4c1de1579ef66e250fb089345bc794a6e91b2f5 100644 (file)
@@ -44,11 +44,17 @@ void                gtk_widget_path_iter_set_widget_type (GtkWidgetPath       *p
                                                           guint                pos,
                                                           GType                type);
 
-G_CONST_RETURN gchar * gtk_widget_path_iter_get_name (const GtkWidgetPath *path,
-                                                      guint                pos);
-void                   gtk_widget_path_iter_set_name (GtkWidgetPath       *path,
-                                                      guint                pos,
-                                                      const gchar         *name);
+G_CONST_RETURN gchar * gtk_widget_path_iter_get_name  (const GtkWidgetPath *path,
+                                                       guint                pos);
+void                   gtk_widget_path_iter_set_name  (GtkWidgetPath       *path,
+                                                       guint                pos,
+                                                       const gchar         *name);
+gboolean               gtk_widget_path_iter_has_name  (const GtkWidgetPath *path,
+                                                       guint                pos,
+                                                       const gchar         *name);
+gboolean               gtk_widget_path_iter_has_qname (const GtkWidgetPath *path,
+                                                       guint                pos,
+                                                       GQuark               qname);
 
 void     gtk_widget_path_iter_add_region    (GtkWidgetPath      *path,
                                              guint               pos,